package com.dongnao.jack.spring.parse;

import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.jboss.netty.util.internal.ConcurrentHashMap;

public class BeanDefinitionParserBuilderMap {

    private static Map<String, BaseBeanDefinitionParseInterface> parseMap = new ConcurrentHashMap<>(4);

    static {
        parseMap.put("registry", new RegistryBeanDefinitionParser());
        parseMap.put("reference", new ReferenceBeanDefinitionParser());
        parseMap.put("protocol", new ProtocolBeanDefinitionParser());
        parseMap.put("service", new ServiceBeanDefinitionParser());
    }

    public static Map<String, BaseBeanDefinitionParseInterface> getInstance() {
        return parseMap;
    }

    public static boolean addParse(String key, BaseBeanDefinitionParseInterface parser) {

        boolean flag = false;
        try {

            if (parseMap.containsKey(key) || StringUtils.isBlank(key)) {
                throw new Exception("数据已经存在");
            }

            parseMap.put(key, parser);

        }
        catch (Exception e) {

        }
        return flag;

    }

}
